﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Text;
using IDAL;
using Model;

namespace DAL
{
    public class RepairItem : BaseRepository<RepairItemInfo>, IRepairItem
    {
        #region 静态变量定义部分
        private const string PARM_REPAIRITEM_PRODUCTSN = "@ProductSN";
        private const string PARM_REPAIRITEM_RECORDTIME = "@RecordTime";
        private const string PARM_REPAIRITEM_REPAIRSTEP = "@RepairStep";

        private const string PARM_REPAIRITEM_PACKAGEPRODUCTSN = "@PackageProductSN";
        #endregion


        #region 检索部分
        public IList<RepairItemInfo> GetRepairItembyLastSN(string productSN)
        {
            SqlParameter parm = GetParameter();
            parm.Value = productSN;
            return ExcuteSqlToGetEntities("RepairItem_selectbyLastSN", parm);
        }

        public RepairItemInfo GetRepairItembyLastSNStep(string productSN, string repairStep)
        {
            SqlParameter[] parms = GetSNStepParameter();
            parms[0].Value = productSN;
            parms[1].Value = repairStep;
            return ExcuteSqlToGetEntity("RepairItem_selectbyLastSNStep", parms);  
        }

        public IList<RepairItemInfo> GetRepairItembySNDT(string productSN, DateTime recordTime)
        {
            SqlParameter[] parms = GetSNDTParameter();
            parms[0].Value = productSN;
            parms[1].Value = recordTime;
            return ExcuteSqlToGetEntities("RepairItem_selectbySNDT", parms);
        }

        public IList<RepairItemInfo> GetRepairItembySN(string productSN)
        {
            SqlParameter parm = GetParameter();
            parm.Value = productSN;
            return ExcuteSqlToGetEntities("RepairItem_selectbySN", parm);
        }

        public IList<RepairItemInfo> GetRepairItembyPackageSN(string packageSN)
        {
            SqlParameter parm = new SqlParameter(PARM_REPAIRITEM_PACKAGEPRODUCTSN, SqlDbType.NVarChar, 50);
            parm.Value = packageSN;
            return ExcuteSqlToGetEntities("RepairItem_selectbyPackageSN", parm);
        }
        #endregion

        #region 参数部分
        public SqlParameter[] GetSNDTParameter()
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
                {
                    new SqlParameter(PARM_REPAIRITEM_PRODUCTSN, SqlDbType.NVarChar, 50),
					new SqlParameter(PARM_REPAIRITEM_RECORDTIME, SqlDbType.DateTime, 8),
                };
            return parms;
        }

        public SqlParameter[] GetSNStepParameter()
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
                {
                    new SqlParameter(PARM_REPAIRITEM_PRODUCTSN, SqlDbType.NVarChar, 50),
					new SqlParameter(PARM_REPAIRITEM_REPAIRSTEP, SqlDbType.NVarChar, 50),
                };
            return parms;
        }

        #endregion

        #region 重写基类部分
        public override RepairItemInfo GetEntityRecord(SqlDataReader rdr)
        {
            RepairItemInfo pro = new RepairItemInfo { ProductSN = rdr.GetValue(0).ToString(), RecordTime = rdr.GetDateTime(1), RepairStep = rdr.GetValue(2).ToString() };
            return pro;
        }

        public override RepairItemInfo GetEntityRecord()
        {
            RepairItemInfo pro = new RepairItemInfo();
            return pro;
        }

        public override SqlParameter GetParameter()
        {
            SqlParameter Parm = new SqlParameter(PARM_REPAIRITEM_PRODUCTSN, SqlDbType.NVarChar, 50);
            return Parm;
        }
        #endregion
    }
}
